#ifndef __IPROGRAM_H__
#define __IPROGRAM_H__

#include "../include/PowerLibraryEngine.h"

class IProgram
{
protected:
    StartDriverParams sdp;
    I2DCameraSceneNode *Camera2D;
    u32 LastFPS;
public:
    IProgram()
    {
        Camera2D = NULL;
    }

    virtual ~IProgram()
    {
    }

    virtual s32 Start()
    {
		InitPLEVideo("General.cfg",&sdp);

		Camera2D = SceneManager->GetSceneGenerator()->GetNew2DCameraSceneNode();
		Camera2D->SetParent(SceneManager);

		SceneManager->GetSceneGenerator()->SetDefaultScene2DParent(Camera2D);
		SceneManager->SetActive2DCamera(Camera2D);
		Camera2D->SetName("DefaultCamera2D");

		pLogRelease << "PLECore initialized" << endl;
		pLogRelease << "Loading modules" << endl;

		s32 id = PackageManager->LoadNewPackage("./SuperYoop.so");

		PackageManager->ShowPackageDetails(id);

		ConfigManager->SetActualSection("GlobalVariables");

		if (ConfigManager->ReadFile("modules.cfg"))
		{
		}
		else
		{
			pLogErrorRelease << "File modules.cfg not found" << endl;
		}

		PackageManager->StartPackage(id);
		return 0;
	}

    virtual bool Loop()
    {
    	u32 ActualNodesRendered = 0;
    	u32 LastNodesRendered = 1;

        while (Device->Update())
        {
            u32 ActualFPS = VideoDriver->GetFPS();
            if (ActualFPS != LastFPS || ActualNodesRendered != LastNodesRendered)
            {
                stringc caption = sdp.TitleDefault + " FPS:";
                caption += UsefulFunctions->ConvertFromNumber(ActualFPS);
                caption += " (";
                caption += UsefulFunctions->ConvertFromNumber(ActualNodesRendered);
                caption += ")";
                Device->SetCaption(caption);
                LastFPS = ActualFPS;
                LastNodesRendered = ActualNodesRendered;
            }

			PackageManager->UpdateAllPackages();
            StateManager->Update();
            GUI->Update();
            VideoDriver->BeginRender();
            ActualNodesRendered = SceneManager->RenderAll(TimeManager->GetActualTime());
            VideoDriver->EndRender();
        }

        return 0;
    }

    virtual bool End()
    {
        DestroyDevice();
		return true;
    }

};

#endif
